﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace GrayParrot.Web
{
    public enum ResponseMessageTypes
    {
        Success = 0,
        Info,
        Warning,
        Error
    }

    public class ResponseMessage
    {
        public ResponseMessageTypes Type { get; set; }
        public string Message { get; set; }

        public ResponseMessage()
        {
        }

        public ResponseMessage(string message, ResponseMessageTypes type)
        {
            this.Message = message;
            this.Type = type;
        }
    }

    public static class Result
    {
        public static string ReturnSuccess(string message)
        {
            return "{ \"d\":true, \"msg\":\"" + message + "\" }";
        }

        public static string ReturnError(string message)
        {
            return "{ \"d\":false, \"msg\":\"" + message + "\" }";
        }

        public static HttpResponseMessage CreateResponseMessage(this HttpRequestMessage request, string message, ResponseMessageTypes messageType)
        {
            HttpResponseMessage retValue = null;

            ResponseMessage m_msg = new ResponseMessage(message, messageType);
            retValue = request.CreateResponse<ResponseMessage>(System.Net.HttpStatusCode.OK, m_msg);

            return retValue;
        }
    }
}
